package com.zyy.smartcity1129.hospital;

import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.zyy.smartcity1129.BaseFragment;
import com.zyy.smartcity1129.R;
import com.zyy.smartcity1129.data.DepartmentInfo;
import com.zyy.smartcity1129.util.Http;
import com.zyy.smartcity1129.util.RvAd;

import java.util.List;

/**
 * @ClassName: DepartmentFragment$
 * @Description: 作用
 * @Author: letquit
 * @CreateDate: 2/12/2021$
 * @Version: 1.0
 */
public class DepartmentFragment extends BaseFragment {
    private RecyclerView rvOnly;

    private RvAd<DepartmentInfo.RowsBean> rvAd;
    public static String patientName = PatientFragment.patientName;
    public static int categoryId;
    public static double money;
    public static String type;
    public static String categoryName;

    @Override
    protected int layId() {
        return R.layout.f_rv_only;
    }

    @Override
    protected String title() {
        return "门诊科室分诊";
    }

    @Override
    protected boolean back() {
        return true;
    }

    @Override
    protected Boolean bottom() {
        return null;
    }

    @Override
    protected void init(View iv) {
        initView(iv);
    }

    private void initView(View iv) {
        rvOnly = (RecyclerView) iv.findViewById(R.id.rvOnly);
        rvOnly.setLayoutManager(new LinearLayoutManager(getContext()));
        th(() -> {
            List<DepartmentInfo.RowsBean> department = Http.getInstance().get("/prod-api/api/hospital/category/list", null, DepartmentInfo.class, 1).getRows();
            ui(() -> {
                initAdapter(department);
                rvOnly.setAdapter(rvAd);
            });
        });
    }

    private void initAdapter(List<DepartmentInfo.RowsBean> department) {
        rvAd = new RvAd<DepartmentInfo.RowsBean>(department, R.layout.rv_base) {
            private void initView(View vi) {
                ig = (ImageView) vi.findViewById(R.id.ig);
                tv1 = (TextView) vi.findViewById(R.id.tv1);
                tv2 = (TextView) vi.findViewById(R.id.tv2);
                tv3 = (TextView) vi.findViewById(R.id.tv3);
                tv4 = (TextView) vi.findViewById(R.id.tv4);
                tv5 = (TextView) vi.findViewById(R.id.tv5);
                tv6 = (TextView) vi.findViewById(R.id.tv6);
                lineRvPatient = (LinearLayout) vi.findViewById(R.id.lineRvPatient);
                imgRvPatient = (ImageView) vi.findViewById(R.id.imgRvPatient);
                tv6.setVisibility(View.GONE);
                tv2.setVisibility(View.GONE);
                tv3.setVisibility(View.GONE);
                tv4.setVisibility(View.GONE);
                tv5.setVisibility(View.GONE);
                ig.setVisibility(View.GONE);
            }

            private TextView tv6;
            private TextView tv5;
            private TextView tv4;
            private TextView tv3;
            private TextView tv2;
            private TextView tv1;
            private ImageView ig;
            private ImageView imgRvPatient;
            private LinearLayout lineRvPatient;

            @Override
            protected void initR(View vi, DepartmentInfo.RowsBean rowsBean, int p) {
                initView(vi);
                tv1.setText(rowsBean.getCategoryName());
                vi.setOnClickListener(view -> {
                    categoryName = rowsBean.getCategoryName();
                    categoryId = rowsBean.getId();
                    money = rowsBean.getMoney();
                    type = rowsBean.getType();
                    add(new Department1Fragment());
                });
            }
        };
    }
}
